/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controllers;

import Entities.Actor;
import Entities.Director;
import Entities.Movie;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.TypedQuery;

/**
 *
 * @author sebastian
 */
public class ActorController {
       EntityManagerFactory emf = Persistence.createEntityManagerFactory("GRLU");
     
  public List<Actor> getActorbyName(String actorName){
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        TypedQuery<Actor> query = (TypedQuery<Actor>) em.createNamedQuery("Actor.findByName", Actor.class);
        query.setParameter("name", actorName);
        List<Actor> resultsActor = query.getResultList();        
        return resultsActor;
    }
  
  public Actor getSingleActor(String nameActor){
   
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        TypedQuery query = (TypedQuery) em.createNamedQuery("Actor.findByName", Actor.class);
        query.setParameter("name", nameActor);
        Actor results = (Actor)query.getSingleResult();
        
        return results;                
    }
    
}
